home *** CD-ROM | disk | FTP | other *** search
/ 10,000 Great Games / 10,000 Great Games.iso / Product / 66 / data1.cab / Source_Files / Src / MainFrm.cpp < prev    next >
C/C++ Source or Header  |  2000-01-16  |  9KB  |  404 lines

  1. #include "stdafx.h"
  2.  
  3. #include "PlayerSelect.h"
  4. #include "RandomProps.h"
  5. #include "QuickStart.h"
  6. #include "Gamma.h"
  7.  
  8. int generate_random = FALSE;
  9.  
  10. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  11.  
  12. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  13.     //{{AFX_MSG_MAP(CMainFrame)
  14.     ON_WM_CREATE()
  15.     ON_COMMAND(ID_VIEW_GAMEAREA, OnViewGameArea)
  16.     ON_UPDATE_COMMAND_UI(ID_VIEW_GAMEAREA, OnUpdateViewGameArea)
  17.     ON_COMMAND(ID_SETTINGS_USEPARALLAXSCROLLING, OnSettingsDetaillevelUseParallaxScrolling)
  18.     ON_UPDATE_COMMAND_UI(ID_SETTINGS_USEPARALLAXSCROLLING, OnUpdateSettingsDetaillevelUseParallaxScrolling)
  19.     ON_COMMAND(ID_SETTINGS_USEVIDEOHARDWARE, OnSettingsDetaillevelUseVideoHardware)
  20.     ON_UPDATE_COMMAND_UI(ID_SETTINGS_USEVIDEOHARDWARE, OnUpdateSettingsDetaillevelUseVideoHardware)
  21.     ON_COMMAND(ID_SETTINGS_LOWDETALLEVEL, OnSettingsLowdetallevel)
  22.     ON_UPDATE_COMMAND_UI(ID_SETTINGS_LOWDETALLEVEL, OnUpdateSettingsLowdetallevel)
  23.     ON_COMMAND(ID_SETTINGS_SELECTPLAYERS, OnSettingsSelectplayers)
  24.     ON_COMMAND(ID_SETTINGS_ALWAYSSHOWPLAYERNAMES, OnSettingsAlwaysshowplayernames)
  25.     ON_UPDATE_COMMAND_UI(ID_SETTINGS_ALWAYSSHOWPLAYERNAMES, OnUpdateSettingsAlwaysshowplayernames)
  26.     ON_COMMAND(ID_VIEW_BACKGROUNDAREA, OnViewBackgroundarea)
  27.     ON_UPDATE_COMMAND_UI(ID_VIEW_BACKGROUNDAREA, OnUpdateViewBackgroundarea)
  28.     ON_COMMAND(ID_RUN_FROMHERE, OnRunFromHere)
  29.     ON_COMMAND(ID_RUN_LEVEL, OnRunLevel)
  30.     ON_UPDATE_COMMAND_UI(ID_VIEW_DEBUGINFO, OnUpdateViewDebuginfo)
  31.     ON_COMMAND(ID_VIEW_DEBUGINFO, OnViewDebuginfo)
  32.     ON_COMMAND(ID_SETTINGS_GAMEOPTIONS_NOARMOR, OnSettingsGameoptionsNoarmor)
  33.     ON_UPDATE_COMMAND_UI(ID_SETTINGS_GAMEOPTIONS_NOARMOR, OnUpdateSettingsGameoptionsNoarmor)
  34.     ON_COMMAND(ID_VIEW_GRID, OnViewGrid)
  35.     ON_UPDATE_COMMAND_UI(ID_VIEW_GRID, OnUpdateViewGrid)
  36.     ON_COMMAND(ID_FILE_NEW_RANDOM, OnFileNewRandom)
  37.     ON_COMMAND(ID_QUICKSTART, OnQuickstart)
  38.     ON_COMMAND(ID_SETTINGS_RANDOMLEVEL, OnSettingsRandomlevel)
  39.     ON_COMMAND(ID_SETTINGS_GAMEOPTIONS_GAMMACORRECTION, OnSettingsGammacorrection)
  40.     //}}AFX_MSG_MAP
  41. END_MESSAGE_MAP()
  42.  
  43. static UINT indicators[] = {ID_SEPARATOR};
  44.  
  45. CMainFrame::CMainFrame()
  46. {
  47. }
  48.  
  49. CMainFrame::~CMainFrame()
  50. {
  51. }
  52.  
  53. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  54. {
  55.     if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  56.         return -1;
  57.     
  58.     if (!m_wndToolBar.Create(this) || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  59.         return -1;
  60.  
  61.     if (!m_wndStatusBar.Create(this) ||    !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT)))
  62.         return -1;
  63.  
  64.     m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
  65.  
  66.     m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  67.     EnableDocking(CBRS_ALIGN_ANY);
  68.     DockControlBar(&m_wndToolBar);
  69.  
  70.     return 0;
  71. }
  72.  
  73. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT &cs)
  74. {
  75.     return CFrameWnd::PreCreateWindow(cs);
  76. }
  77.  
  78. #ifdef _DEBUG
  79.  
  80. void CMainFrame::AssertValid() const
  81. {
  82.     CFrameWnd::AssertValid();
  83. }
  84.  
  85. void CMainFrame::Dump(CDumpContext& dc) const
  86. {
  87.     CFrameWnd::Dump(dc);
  88. }
  89.  
  90. #endif
  91.  
  92. BOOL CMainFrame::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 
  93. {
  94.     return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
  95. }
  96.  
  97. void CMainFrame::OnViewBackgroundarea() 
  98. {
  99.     view_backgroundarea = !view_backgroundarea;
  100.  
  101.     back_surface->all_dirty();
  102.  
  103.     cEditable::editables_layer_change();
  104.  
  105.     Invalidate();
  106. }
  107.  
  108. void CMainFrame::OnUpdateViewBackgroundarea(CCmdUI* pCmdUI) 
  109. {
  110.     pCmdUI->SetCheck(view_backgroundarea || no_parallax);
  111.     pCmdUI->Enable(!no_parallax);    
  112. }
  113.  
  114. void CMainFrame::OnViewGameArea() 
  115. {
  116.     view_gamearea = !view_gamearea;    
  117.  
  118.     game_surface->all_dirty();
  119.  
  120.     cEditable::editables_layer_change();
  121.  
  122.     Invalidate();
  123. }
  124.  
  125. void CMainFrame::OnUpdateViewGameArea(CCmdUI* pCmdUI) 
  126. {
  127.     pCmdUI->SetCheck(view_gamearea || no_parallax);    
  128.     pCmdUI->Enable(!no_parallax);
  129. }
  130.  
  131. void CMainFrame::OnSettingsDetaillevelUseParallaxScrolling() 
  132. {
  133.     CWaitCursor wait;
  134.  
  135.     save_level(autosave_level);
  136.     
  137.     deinit_game_loop();
  138.     deinit_game_data();
  139.     deinit_directdraw();
  140.  
  141.     no_parallax = !no_parallax;    
  142.  
  143.     if (no_parallax)
  144.         warning("This mode is meant to speed up the game on slow computers.\n\n"
  145.                 "THE LEVEL EDITOR WILL GIVE INPREDICTABLE RESULTS.\n\n"
  146.                 "DO NOT EDIT IN THIS MODE!!");
  147.  
  148.     init_directdraw_inawin();
  149.     init_game_data();
  150.     init_game_loop();
  151.  
  152.     load_level(autosave_level);
  153.  
  154.     Invalidate();
  155. }
  156.  
  157. void CMainFrame::OnUpdateSettingsDetaillevelUseParallaxScrolling(CCmdUI* pCmdUI) 
  158. {
  159.     pCmdUI->SetCheck(!no_parallax);    
  160. }
  161.  
  162. void CMainFrame::OnSettingsDetaillevelUseVideoHardware() 
  163. {
  164.     CWaitCursor wait;
  165.     
  166.     save_level(autosave_level);
  167.     
  168.     deinit_game_loop();
  169.     deinit_game_data();    
  170.     deinit_directdraw();
  171.         
  172.     no_blit_hardware = !no_blit_hardware;
  173.  
  174.     init_directdraw_inawin();
  175.     init_game_data();
  176.     init_game_loop();
  177.  
  178.     load_level(autosave_level);
  179.  
  180.     Invalidate();
  181. }
  182.  
  183. void CMainFrame::OnUpdateSettingsDetaillevelUseVideoHardware(CCmdUI* pCmdUI) 
  184. {
  185.     pCmdUI->SetCheck(!no_blit_hardware && hardware_blit_caps);
  186.     pCmdUI->Enable(hardware_blit_caps);
  187. }
  188.  
  189. void CMainFrame::OnSettingsLowdetallevel() 
  190. {
  191.     low_detail_level = !low_detail_level;
  192. }
  193.  
  194. void CMainFrame::OnUpdateSettingsLowdetallevel(CCmdUI* pCmdUI) 
  195. {
  196.     pCmdUI->SetCheck(low_detail_level);    
  197. }
  198.  
  199. void CMainFrame::OnUpdateViewDebuginfo(CCmdUI* pCmdUI) 
  200. {
  201.     pCmdUI->SetCheck(debug);        
  202. }
  203.  
  204. void CMainFrame::OnViewDebuginfo() 
  205. {
  206.     debug = !debug;    
  207.  
  208.     Invalidate();
  209. }
  210.  
  211. void CMainFrame::OnSettingsSelectplayers() 
  212. {
  213.     CPlayerSelect p;
  214.     p.DoModal();
  215. }
  216.  
  217. void CMainFrame::OnSettingsAlwaysshowplayernames() 
  218. {
  219.     names_visible = !names_visible;    
  220. }
  221.  
  222. void CMainFrame::OnUpdateSettingsAlwaysshowplayernames(CCmdUI* pCmdUI) 
  223. {
  224.     pCmdUI->SetCheck(names_visible);    
  225. }
  226.  
  227. void CMainFrame::OnSettingsRandomlevel() 
  228. {
  229.     CRandomProps r;
  230.     r.DoModal();    
  231. }
  232.  
  233. void CMainFrame::OnQuickstart() 
  234. {
  235.     CQuickStart q;
  236.     q.DoModal();    
  237. }
  238.  
  239. void CMainFrame::OnRunFromHere() 
  240. {    
  241.     int start;
  242.  
  243.     // Save the level
  244.  
  245.     SetCursor(LoadCursor(0, IDC_WAIT));
  246.  
  247.     start = game_surface->start;
  248.     save_level(autosave_level);
  249.  
  250.     // Do the game
  251.  
  252.     SetCursor(0);
  253.  
  254.     game_loop();    
  255.  
  256.     SetCursor(LoadCursor(0, IDC_WAIT));
  257.  
  258.     // Restore previous state
  259.  
  260.     deinit_game_loop();
  261.     init_game_loop();
  262.     load_level(autosave_level);
  263.     gamewindow->ScrollTo(0, start);
  264.  
  265.     SetCursor(LoadCursor(0, IDC_ARROW));
  266.  
  267.     // Redraw window
  268.  
  269.     Invalidate();    
  270. }
  271.  
  272. void CMainFrame::OnRunLevel() 
  273. {
  274.     int start;
  275.  
  276.     // Save current level
  277.  
  278.     SetCursor(LoadCursor(0, IDC_WAIT));
  279.  
  280.     start = game_surface->start;
  281.     save_level(autosave_level);
  282.  
  283.     // Deinit game
  284.  
  285.     deinit_game_loop();
  286.     deinit_game_data();    
  287.     deinit_directdraw();
  288.  
  289.     // Reinit game in full screen mode
  290.  
  291.     inawin = FALSE;
  292.  
  293.     init_directdraw_notinawin();    
  294.     init_game_data();
  295.  
  296.     // Load level
  297.  
  298.     init_game_loop();
  299.     load_level(started_with_quickstart? construct("%s.bdl", quickstart_level) : autosave_level);
  300.  
  301.     // Run level
  302.  
  303.     SetCursor(0);
  304.  
  305.     game_loop();
  306.     
  307.     SetCursor(LoadCursor(0, IDC_WAIT));
  308.  
  309.     // Deinit game
  310.  
  311.     deinit_game_loop();
  312.     deinit_game_data();
  313.     deinit_directdraw();
  314.  
  315.     // Reinit game in windowed mode
  316.  
  317.     inawin = TRUE;
  318.  
  319.     // Resize window
  320.  
  321.     ResizeToFitGameArea();
  322.     
  323.     // Reinit the game in a window
  324.  
  325.     init_directdraw_inawin();
  326.     init_game_data();
  327.     init_game_loop();
  328.  
  329.     // Reload the level
  330.  
  331.     load_level(autosave_level);
  332.     gamewindow->ScrollTo(0, start);
  333.     
  334.     SetCursor(LoadCursor(0, IDC_ARROW));
  335.     
  336.     // Redraw window
  337.  
  338.     Invalidate();    
  339.  
  340.     // Do Quickstart menu again?
  341.  
  342.     if (started_with_quickstart)
  343.     {
  344.         PostMessage(WM_COMMAND, ID_QUICKSTART, 0);
  345.     
  346.         started_with_quickstart = FALSE;
  347.     }
  348. }
  349.  
  350. void CMainFrame::ResizeToFitGameArea()
  351. {
  352.     // Resize so that game are will fit exactly in window
  353.  
  354.     WINDOWPLACEMENT    mw;
  355.     mainwindow->GetWindowPlacement(&mw);
  356.     
  357.     WINDOWPLACEMENT gw;
  358.     gamewindow->GetWindowPlacement(&gw);
  359.     
  360.     CRect gw_wanted(0, 0, SCREEN_X, SCREEN_Y);
  361.     gamewindow->CalcWindowRect(&gw_wanted, CWnd::adjustOutside);
  362.  
  363.     int dx = (mw.rcNormalPosition.right - mw.rcNormalPosition.left) + (gw_wanted.right - gw_wanted.left) - (gw.rcNormalPosition.right - gw.rcNormalPosition.left) - 1;
  364.     int dy = (mw.rcNormalPosition.bottom - mw.rcNormalPosition.top) + (gw_wanted.bottom - gw_wanted.top) - (gw.rcNormalPosition.bottom - gw.rcNormalPosition.top) - 1;
  365.  
  366.     mainwindow->MoveWindow(0, 0, dx, dy);        
  367.     mainwindow->CenterWindow();
  368. }
  369.  
  370. void CMainFrame::OnSettingsGameoptionsNoarmor() 
  371. {
  372.     no_armor = !no_armor;
  373. }
  374.  
  375. void CMainFrame::OnUpdateSettingsGameoptionsNoarmor(CCmdUI* pCmdUI) 
  376. {
  377.     pCmdUI->SetCheck(no_armor);
  378. }
  379.  
  380. void CMainFrame::OnViewGrid() 
  381. {
  382.     view_grid = !view_grid;
  383.     
  384.     Invalidate();
  385. }
  386.  
  387. void CMainFrame::OnUpdateViewGrid(CCmdUI* pCmdUI) 
  388. {
  389.     pCmdUI->SetCheck(view_grid);    
  390. }
  391.  
  392. void CMainFrame::OnFileNewRandom() 
  393. {
  394.     generate_random = TRUE;
  395.  
  396.     PostMessage(WM_COMMAND, ID_FILE_NEW, 0);
  397. }
  398.  
  399. void CMainFrame::OnSettingsGammacorrection() 
  400. {
  401.     CGamma g;
  402.     g.DoModal();
  403. }
  404.